package com.tangzx.builder.visitor;

import java.util.LinkedList;

import macromedia.abc.DecoderException;
import macromedia.abc.Visitor;
import com.tangzx.builder.abc.AbcCPool;
import com.tangzx.builder.abc.string.AbcString;
import com.tangzx.builder.abc.string.MultiName;

public class ABCVisitorExt implements Visitor{
	protected AbcCPool cpool;
	protected IScope currentScope = new Scope();
	protected LinkedList<IScope> scopeStack = new LinkedList<IScope>();
	protected LinkedList<IScope> paramStack = new LinkedList<IScope>();
	
	public ABCVisitorExt(AbcCPool cpool)
	{
		this.cpool = cpool;
		pushScope(currentScope);
	}
	
	public void pushScope(IScope scope) {
		scopeStack.push(scope);
	}
	
	public void push(IScope param) {
		paramStack.push(param);
		System.out.println("\t\t\t//push, stackSize:" + paramStack.size() + ", obj:" + param);
	}
	
	public IScope pop() {
		return paramStack.pop();
	}
	
	public IScope peekLastParam() {
		return paramStack.peekLast();
	}
	
	public void OP_add() {
		
	}

	
	public void OP_add_i() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_add_p(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_applytype(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_astype(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_astypelate() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_bitand() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_bitnot() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_bitor() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_bitxor() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_bkpt() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_bkptline() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_call(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_callmethod(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_callproperty(int multiname, int arg_count) {
		MultiName mn = cpool.getMultiName(multiname);
		System.out.println("OP_callproperty:" + mn);
	}

	
	public void OP_callproplex(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_callpropvoid(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_callstatic(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_callsuper(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_callsupervoid(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_checkfilter() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_coerce(int name) {
		MultiName nameObj = cpool.getMultiName(name);
		pop();
		push(new Scope(nameObj));
		System.out.println("OP_coerce, type:" + nameObj);
	}

	
	public void OP_coerce_a() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_coerce_b() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_coerce_d() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_coerce_i() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_coerce_o() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_coerce_s() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_coerce_u() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_construct(int argNum) {
		paramStack.poll();
		IScope receiver = pop();
		//params:
		for (int i = 0; i < argNum; i ++)
			OP_pop();
		
		push(receiver);
		System.out.println("OP_construct, argNum:" + argNum + "");
	}

	
	public void OP_constructprop(int name, int argNum) {
		for (int i = 0; i < argNum; i ++)
			OP_pop();
		IScope nameObj = pop();
		System.out.println("OP_constructprop, argNum:" + argNum + ", name:" + nameObj);
		push(nameObj);
	}

	
	public void OP_constructsuper(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_convert_b() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_convert_d() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_convert_i() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_convert_m() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_convert_m_p(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_convert_o() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_convert_s() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_convert_u() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_debug(int arg0, int arg1, int arg2, int arg3) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_debugfile(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_debugline(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_declocal(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_declocal_i(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_declocal_p(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_decrement() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_decrement_i() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_decrement_p(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_deldescendants() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_deleteproperty(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_divide() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_divide_p(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_dup() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_dxns(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_dxnslate() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_equals() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_esc_xattr() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_esc_xelem() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_finddef(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_findproperty(int value) {
		MultiName mn = cpool.getMultiName(value);
		System.out.println("OP_findproperty:" + mn);
		push(new Scope(mn));
	}

	
	public void OP_findpropstrict(int multiname) {
		MultiName mn = cpool.getMultiName(multiname);
		push(new Scope(mn));
		System.out.println("OP_findpropstrict:" + mn);
	}

	
	public void OP_getdescendants(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_getglobalscope() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_getglobalslot(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_getlex(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_getlocal(int value) {
		currentScope = scopeStack.get(value);
		push(currentScope);
		System.out.println("OP_getlocal, obj:" + currentScope + ", index:" + value + ", scopeStackSize:" + scopeStack.size() + ", paramStackSie:" + paramStack.size());
	}

	
	public void OP_getlocal0() {
		OP_getlocal(0);
	}

	
	public void OP_getlocal1() {
		OP_getlocal(1);
	}

	
	public void OP_getlocal2() {
		OP_getlocal(2);
	}

	
	public void OP_getlocal3() {
		OP_getlocal(3);
	}

	
	public void OP_getproperty(int value) {
		MultiName mn = cpool.getMultiName(value);
		if (currentScope.getValue() instanceof MultiName) {
			MultiName m = (MultiName) currentScope.getValue();
			if (m.getName().toString().equals("XML")) {
				System.out.println("是XML啊.");
			}
		}
		push(new Scope(mn));
		System.out.println("OP_getproperty:" + mn + ", current:" + currentScope);
	}

	
	public void OP_getscopeobject(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_getslot(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_getsuper(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_greaterequals() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_greaterthan() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_hasnext() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_hasnext2(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_ifeq(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_iffalse(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_ifge(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_ifgt(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_ifle(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_iflt(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_ifne(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_ifnge(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_ifngt(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_ifnle(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_ifnlt(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_ifstricteq(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_ifstrictne(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_iftrue(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_in() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_inclocal(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_inclocal_i(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_inclocal_p(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_increment() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_increment_i() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_increment_p(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_initproperty(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_instanceof() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_istype(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_istypelate() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_jump(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_kill(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_label() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_lessequals() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_lessthan() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_lf32() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_lf64() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_li16() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_li32() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_li8() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_lookupswitch(int arg0, int[] arg1, int arg2, int arg3) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_lshift() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_modulo() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_modulo_p(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_multiply() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_multiply_i() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_multiply_p(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_negate() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_negate_i() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_negate_p(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_newactivation() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_newarray(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_newcatch(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_newclass(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_newfunction(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_newobject(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_nextname() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_nextvalue() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_nop() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_not() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_pop() {
		IScope param = pop();
		System.out.println("OP_pop, param:" + param + ", stackSize:" + paramStack.size());
	}

	
	public void OP_popscope() {
		scopeStack.pop();
		currentScope = scopeStack.peekLast();
		System.out.println("OP_popscope, current:" + currentScope);
		OP_pop();
	}

	
	public void OP_pushbyte(int value) {
		push(new Scope(value));
	}

	
	public void OP_pushconstant(int value) {
		push(new Scope(value));
	}

	
	public void OP_pushdecimal(int value) {
		push(new Scope(value));
	}

	
	public void OP_pushdnan() {
		push(new Scope("dNaN"));
	}

	
	public void OP_pushdouble(int value) {
		push(new Scope(value));
	}

	
	public void OP_pushfalse() {
		push(new Scope(false));
	}

	
	public void OP_pushint(int value) {
		push(new Scope(value));
	}

	
	public void OP_pushnamespace(int value) {
		push(new Scope(value));
	}

	
	public void OP_pushnan() {
		push(new Scope("NaN"));
		
	}

	
	public void OP_pushnull() {
		push(new Scope("isNull"));
	}

	
	public void OP_pushscope() {
		pop();
		pushScope(new Scope());
		System.out.println("OP_pushscope");
	}

	
	public void OP_pushshort(int value) {
		push(new Scope(value));
	}

	
	public void OP_pushstring(int index) {
		AbcString as = cpool.getString(index);
		as.vo.pushString(true);
		push(new Scope(as));
		System.out.println("OP_pushstring, " + as);
	}

	
	public void OP_pushtrue() {
		push(new Scope(true));
	}

	
	public void OP_pushuint(int value) {
		push(new Scope(value));
	}

	
	public void OP_pushundefined() {
		push(new Scope("is Undefined"));
	}

	
	public void OP_pushwith() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_returnvalue() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_returnvoid() {
		// TODO Auto-generated method stub
		System.out.println(paramStack.size() + "####################################################################OP_returnvoid");
	}

	
	public void OP_rshift() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_setglobalslot(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_setlocal(int value) {
		IScope local = pop();
		while (scopeStack.size() <= value) {
			scopeStack.push(new Scope("###"));
		}
		scopeStack.set(value, local);
		System.out.println("OP_setlocal:" + value + ", obj:" + currentScope);
	}

	
	public void OP_setlocal0() {
		OP_setlocal(0);
	}

	
	public void OP_setlocal1() {
		OP_setlocal(1);
	}

	
	public void OP_setlocal2() {
		OP_setlocal(2);
	}

	
	public void OP_setlocal3() {
		OP_setlocal(3);
	}

	
	public void OP_setproperty(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_setslot(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_setsuper(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_sf32() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_sf64() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_si16() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_si32() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_si8() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_strictequals() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_subtract() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_subtract_i() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_subtract_p(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_swap() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_sxi1() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_sxi16() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_sxi8() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_throw() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_timestamp() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_typeof() {
		// TODO Auto-generated method stub
		
	}

	
	public void OP_urshift() {
		// TODO Auto-generated method stub
		
	}

	
	public void classTrait(int arg0, int arg1, int arg2, int arg3, int[] arg4)
			throws DecoderException {
		// TODO Auto-generated method stub
		System.out.println("classTrait");
	}

	
	public void endClass() {
		// TODO Auto-generated method stub
		
	}

	
	public void endExceptions() {
		// TODO Auto-generated method stub
		
	}

	
	public void endInstance() {
		// TODO Auto-generated method stub
		
	}

	
	public void endMethodBody() {
		// TODO Auto-generated method stub
		
	}

	
	public void endOpcodes() {
		// TODO Auto-generated method stub
		
	}

	
	public void endScript() {
		// TODO Auto-generated method stub
		
	}

	
	public void exception(long arg0, long arg1, long arg2, int arg3, int arg4) {
		// TODO Auto-generated method stub
		
	}

	
	public void functionTrait(int arg0, int arg1, int arg2, int arg3, int[] arg4)
			throws DecoderException {
		// TODO Auto-generated method stub
		System.out.println("functionTrait");
	}

	
	public void metadataInfo(int arg0, int arg1, int[] arg2, int[] arg3)
			throws DecoderException {
		// TODO Auto-generated method stub
		System.out.println("metadataInfo");
	}

	
	public void methodInfo(int arg0, int[] arg1, int arg2, int arg3,
			int[] arg4, int[] arg5, int[] arg6) throws DecoderException {
		// TODO Auto-generated method stub
		System.out.println("methodInfo");
	}

	
	public void methodTrait(int arg0, int arg1, int arg2, int arg3, int[] arg4)
			throws DecoderException {
		// TODO Auto-generated method stub
		System.out.println("methodTrait");
	}

	
	public void slotTrait(int arg0, int arg1, int arg2, int arg3, int arg4,
			int arg5, int[] arg6) throws DecoderException {
		// TODO Auto-generated method stub
		System.out.println("slotTrait");
	}

	
	public void startClass(int arg0, int arg1) throws DecoderException {
		System.out.println("startClass");
	}

	
	public void startExceptions(int arg0) {
		// TODO Auto-generated method stub
		System.out.println("startExceptions");
	}

	
	public void startInstance(int arg0, int arg1, boolean arg2, boolean arg3,
			boolean arg4, int[] arg5, int arg6, int arg7)
			throws DecoderException {
		// TODO Auto-generated method stub
		System.out.println("startInstance");
	}

	
	public void startMethodBody(int arg0, int arg1, int arg2, int arg3,
			int arg4, int arg5, long arg6) throws DecoderException {
		System.out.println("startMethodBody");
	}

	
	public void startOpcodes(int arg0) {
		// TODO Auto-generated method stub
		System.out.println("startOpcodes");
	}

	
	public void startScript(int arg0) {
		// TODO Auto-generated method stub
		System.out.println("startScript");
	}

	
	public void target(int arg0) {
		// TODO Auto-generated method stub
		
	}

	
	public void traitCount(int arg0) {
		// TODO Auto-generated method stub
		
	}
    
}
